package weaver.interfaces.jjy.duss.hr;

import com.sap.mw.jco.JCO;
import weaver.interfaces.jjy.duss.util.SAPConnPool;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @program: ecology-9-demo
 * @description: 筛选福利人员名单
 * @author: Dusongsong
 * @create: 2019-12-07
 */

public class ZFM_HR_063 {
    public Map execute(List<Map<String, String>> mapList) {
        SAPConnPool SAPConn = new SAPConnPool();
        JCO.Client myConnection = SAPConn.getConnection();
        JCO.Function bapi = SAPConn.excuteBapi( "ZFM_HR_063" );
        JCO.ParameterList input = bapi.getImportParameterList();//输入参数和结构处理
        JCO.ParameterList inputtable = bapi.getTableParameterList();//输入表的处理
        //入参为表
        JCO.Table t1 = inputtable.getTable( "IT_TABLE" );
        for (Map<String, String> map : mapList) {
            t1.appendRow();
            t1.setValue( map.get( "GJAHR" ), "GJAHR" );   //年份
            t1.setValue( map.get( "JQFL" ), "JQFL" );     //假期类型
            t1.setValue( map.get( "PERNR" ), "PERNR" );   //人员编码
            t1.setValue( map.get( "FLFW" ), "FLFW" );     //部门规定福利范围
            t1.setValue( map.get( "FLFW1" ), "FLFW1" );   //部门上报福利范围
            t1.setValue( map.get( "FLKH" ), "FLKH" );     //福利卡号
        }

        System.out.println( "mapList" + mapList.toString() );
        //执行函数
        myConnection.execute( bapi );
        JCO.ParameterList out = bapi.getExportParameterList();//输出参数和结构处理
        JCO.ParameterList Table00 = bapi.getTableParameterList();//输出表的处理

        //返回处理结果以及日志
        JCO.Table stu = inputtable.getTable( "IT_TABLE" );
        Map<String, String> mapreturn = new HashMap<>();
        String flag = (String) stu.getValue( "ZFLAG" );
        String message = (String) stu.getValue( "ZMESG" );
        mapreturn.put( "flag", flag );
        mapreturn.put( "message", message );
        System.out.println( "返回结果：" + mapreturn );
        JCO.releaseClient( myConnection );
        return mapreturn;
    }

}
